<?php

namespace app\common\model;

use think\Paginator;
use app\common\model\search\DiseaseTypeSearch;

class DiseaseType extends BaseModel
{
    protected $name = "disease_type";
    use DiseaseTypeSearch;

    /**
     * 获取列表
     * @param array $where 查询条件
     * @param string $field 字段
     * @return Paginator
     */
    public function getLists(array $where=[], string $field="*"): Paginator
    {
        return $this->mongoSearch()
            ->where($where)
            ->field($field)
            ->order('created_at', 'desc')
            ->paginate($this->pageLimit);
    }

    /**
     * 添加数据
     * @param array $data
     * @return int
     */
    public function addData(array $data): int
    {
        //添加时销毁自带的主键id
        unset($data['id']);
        return $this->save($data);
    }

    /**
     * 更新数据
     * @param array $data
     * @return bool
     */
    public function saveData($id, array $data): bool
    {
        $model = self::find($id);
        return $model->save($data);
    }

     /**
     * 获取数据
     * @param array $where 条件

     * @return array
     */
    public function getConditionData(array $where = [],  $field = "*"): array
    {

        return $this->field($field)->where($where)->select()->toArray();
    }

    /**
     * 获取一条数据
     * @param array $where 条件
     * @param string $field 字段
     */
    public function getConditionOne(array $where = [], string $field = "*")
    {
        return $this->field($field)->where($where)->find();
    }
}
